package com.test.service;


import com.test.dao.StuOperatDao;
import com.test.entity.CompAllInfoDto;
import com.test.entity.RecruitDto;
import com.test.entity.StuAllInfoDto;
import com.test.entity.TimeTableDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class StuOperatService {
    @Autowired
    private StuOperatDao stuOperatDao;

    public StuAllInfoDto selectStuByAcount(String acount) {
        StuAllInfoDto stuAllInfoDto = stuOperatDao.selectStuByAcount(acount);
        return stuAllInfoDto;
    }

    public String selectUacount(String acount) {
        String u_acount = stuOperatDao.selectUacount(acount);
        return u_acount;
    }

    public StuAllInfoDto wxselectStuInfoByWx(String wx_acount) {
        StuAllInfoDto stuAllInfoDto = stuOperatDao.wxselectStuInfoByWx(wx_acount);
        return stuAllInfoDto;
    }

    public String getUpassword(String acount) {
        String uPassword = stuOperatDao.getUpassword(acount);
        return uPassword;
    }


    public void insertCodePath(String acount, String pathName) {
        stuOperatDao.insertCodePath(acount, pathName);

    }

    public String selectStuCode(String stu_code) {
        String u_acount = stuOperatDao.selectStuAcount(stu_code);
        if (u_acount != null && !"".equals(u_acount)) {
            String codePath = stuOperatDao.selectStuCode(u_acount);
            if (codePath != null && !"".equals(codePath)) {
                return codePath;
            } else {
                return null;
            }
        } else {
            return null;
        }
    }

    public static String stuAcount = null;

    public String scanLogin(String wx_acount, HttpSession session) {
        try {
            String u_acount = stuOperatDao.scanLogin(wx_acount);
            String result = stuOperatDao.selectStuName(u_acount);
            if (u_acount != null && !"".equals(u_acount)) {
                session.setAttribute("stu_u_acount", u_acount);
                stuAcount = u_acount;
                return result + "同学";
            } else {
                return "扫码失败";
            }
        } catch (Exception e) {
            return "扫码失败";
        }
    }

    public String delbangdingxitong(String wx_acount) {
        int result = stuOperatDao.delbangdingxitong(wx_acount);
        if (result > 0) {

            return "解除成功";
        } else {
            return "解除失败";
        }
    }


    public String dataBangding(String u_acount, String u_password, String wx_acount) {
        int flog = 1;
        if (u_acount == null || "".equals(u_acount)) {
            flog = 0;
        }
        if (u_password == null || "".equals(u_password)) {
            flog = 0;
        }
        if (wx_acount == null || "".equals(wx_acount)) {
            flog = 0;
        }
        if (flog > 0) {
            try {
                int result = stuOperatDao.selectXtUser(u_acount, u_password);
                if (result > 0) {
                    int inresult = 0;
                    try {
                        inresult = stuOperatDao.insertXtUser(u_acount, wx_acount);
                    } catch (Exception e) {
                        return "已经绑定";
                    }
                    if (inresult > 0) {
                        return "绑定成功";
                    } else {
                        return "绑定失败";
                    }

                } else {
                    return "用户名不存在";
                }
            } catch (Exception e) {
                return "用户名不存在";
            }
        } else {
            return "用户名或密码不能为空";
        }
    }

    public StuAllInfoDto selectStuByStuCode(String acount) {
        StuAllInfoDto stuAllInfoDto = stuOperatDao.selectStuByStuCode(acount);
        return stuAllInfoDto;
    }


    public int insertStuResume(StuAllInfoDto stuAllInfoDto) {
        int result = stuOperatDao.insertStuResume(stuAllInfoDto);
        return result;
    }

    public int insertTimeTableInfo(TimeTableDto timeTableDto) {
        int result = stuOperatDao.insertTimeTableInfo(timeTableDto);
        return result;
    }

    public void deleteStuResume(String acount) {
        stuOperatDao.deleteStuResume(acount);
    }


    public void deleteTimeTableInfo(String acount) {
        stuOperatDao.deleteTimeTableInfo(acount);
    }


    public TimeTableDto selectTimeTableInfo(String u_acount) {
        TimeTableDto timeTableDto = stuOperatDao.selectTimeTableInfo(u_acount);
        return timeTableDto;
    }


    public void cleanTimeTableInfo() {
        stuOperatDao.cleanTimeTableInfo();
    }

    public List<CompAllInfoDto> selectAllComp(CompAllInfoDto compAllInfoDto) {
        List<CompAllInfoDto> allstulist = stuOperatDao.selectAllComp(compAllInfoDto);

        return allstulist;
    }

    public List<RecruitDto> selectAllMenHuInfo(RecruitDto recruitDto) {
        List<RecruitDto> allstulist = stuOperatDao.selectAllMenHuInfo(recruitDto);

        return allstulist;
    }


    public List<CompAllInfoDto> selectAttentAllComp(CompAllInfoDto compAllInfoDto, String acount) {
        List<CompAllInfoDto> allstulist = stuOperatDao.selectAttentAllComp(compAllInfoDto, acount);
        return allstulist;
    }


    public List<CompAllInfoDto> selectOnline(String acount) {
        List<CompAllInfoDto> allstulist = stuOperatDao.selectOnline(acount);
        return allstulist;
    }


    public int selectcompYuyueInfo(String acount, String stu_acount,String wangshenjob) {
        int result = stuOperatDao.selectcompYuyueInfo(acount, stu_acount,wangshenjob);
        return result;
    }

    public int selectcompYuyuemianInfo(String acount, String stu_acount,String wangshenjob) {
        int result = stuOperatDao.selectcompYuyuemianInfo(acount, stu_acount,wangshenjob);
        return result;
    }


    public int stuAttentComp(String stu_acount, String comp_acount) {
        int result = 0;
        List<String> checkList = stuOperatDao.checkAttentComp(stu_acount);
        if (checkList.size() > 0) {
            int num = 0;
            for (int i = 0; i < checkList.size(); i++) {

                if (checkList.get(i).equals(comp_acount)) {
                    num++;
                } else {
                    result = 2;
                }
            }
            if (num < 1) {
                result = stuOperatDao.stuAttentComp(stu_acount, comp_acount);
            }
        } else {
            result = stuOperatDao.stuAttentComp(stu_acount, comp_acount);
        }

        return result;
    }


    public int stuOnlineApplication(String stu_acount, String comp_acount, String wangshenjob) {
        int result = 0;
        try {
            result = stuOperatDao.stuOnlineApplication(stu_acount, comp_acount, wangshenjob);
        } catch (Exception e) {
            result = 2;
        }
        return result;
    }


    public int delstuAttentComp(String acount, String comp_acount) {
        int result = stuOperatDao.delstuAttentComp(acount, comp_acount);
        return result;
    }


}
